#!/bin/sh

if [ $# == 0 ]
then
  echo "Usage: contest.sh 'polygon-contest-id' 'ejudge-contest-dir'"
  echo ""
  echo "This command line deploys/updates contest in the current directory for Ejudge installation from Polygon"
  echo ""
  exit 65
fi

rm -rf $2
scp -r ejudge@10.0.0.35:/var/lib/ejudge/$2 .

date=$(date +%x_%X)
mkdir -p ~/.polygon/$2/$date
cp -r $2 ~/.polygon/$2/$date

if [ $# == 2 ]
then
  pgn.sh -login admin -password zanzibar edc -contestDir $2 -url http://10.0.0.1:8080/polygon/c/$1
else
  pgn.sh -login admin -password zanzibar edc -contestDir $2 -url http://10.0.0.1:8080/polygon/c/$1 -problemLetters $3
fi

scp -r $2 ejudge@10.0.0.35:/var/lib/ejudge
